package org.leyi.shop.common.handle;

import lombok.extern.slf4j.Slf4j;
import org.leyi.shop.common.exception.BusinessException;
import org.leyi.shop.common.response.BaseResponse;
import org.leyi.shop.common.response.EnumResponse;
import org.leyi.shop.util.BaseResponseUtils;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 *
 * description:  全局异常处理器
 *<br> create 2024/5/4-23:51
 * @author  lenovo
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public BaseResponse<String> handleHttpMessageNotReadableException(Exception ex) {
        return BaseResponseUtils.error(EnumResponse.PARAMETER_ERR,"输入的参数有误,请仔细检查一下参数");
    }
    @ExceptionHandler(BusinessException.class)
    public BaseResponse<String> businessExceptionHandle(Exception e)
    {
      log.error(e.getMessage(),e);
      return BaseResponseUtils.error(e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<String> runtimeExceptionHandle(Exception e)
    {
        log.error(e.getMessage(),e);
        return BaseResponseUtils.error(EnumResponse.SYSTEM_ERR);
    }

}
